<template>
  <div class="online-service">

    <!-- 服务提示 -->
    <div class="service-info">
      <p>上门维修在线客服为您服务</p>
    </div>

    <!-- 聊天内容 -->
    <div class="chat-content">
      <!-- 客服消息 -->
      <div class="message customer-service">
        <img class="avatar" :src="uploadIcon" alt="客服头像" />
        <div class="message-bubble">
          <p>您好，很高兴为您服务，请问有什么可以帮您？</p>
        </div>
      </div>

      <!-- 用户消息展示 -->
      <div v-for="(message, index) in userMessages" :key="index" class="message user">
        <div class="message-bubble">
          <p>{{ message }}</p>
        </div>
        <img class="avatar" :src="uploadIcons" alt="用户头像" />
      </div>
    </div>

    <!-- 输入框和功能按钮 -->
    <div class="chat-input-area">
      <button class="voice-btn">🎤</button>
      <input type="text" v-model="newMessage" placeholder="输入消息..." class="message-input" />
      <button class="emoji-btn">😊</button>
      <button class="add-btn">➕</button>
      <button class="send-btn" @click="sendMessage">发送</button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      newMessage: '', // 输入框中的消息内容
      userMessages: [] ,// 存储用户发送的消息
	  uploadIcon:"/static/customer.png",
	  uploadIcons:"/start/user.png"
    };
  },
  methods: {
    sendMessage() {
      if (this.newMessage.trim()) {
        // 将用户输入的消息添加到消息列表
        this.userMessages.push(this.newMessage.trim());
        this.newMessage = ''; // 发送后清空输入框
      }
    }
  }
};
</script>

<style scoped>
.online-service {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background-color: #f5f5f5;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  background-color: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.chat-header h2 {
  margin: 0;
  font-size: 18px;
}

.back-btn, .more-options-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
}

.service-info {
  text-align: center;
  padding: 10px;
  font-size: 14px;
  color: #888;
}

.chat-content {
  flex: 1;
  padding: 10px;
  overflow-y: auto;
}

.message {
  display: flex;
  margin-bottom: 10px;
}

.message.customer-service {
  flex-direction: row;
}

.message.user {
  flex-direction: row-reverse;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin-left: 10px;
}

.message-bubble {
  background-color: #ffffff;
  padding: 10px;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  max-width: 70%;
}

.chat-input-area {
  display: flex;
  align-items: center;
  padding: 10px;
  background-color: #ffffff;
  box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.1);
}

.voice-btn, .emoji-btn, .add-btn, .send-btn {
  background: none;
  border: none;
  font-size: 24px;
  margin-right: 10px;
  cursor: pointer;
}

.message-input {
  flex: 1;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 20px;
}
</style>
